package com.example.demo.common;

import com.example.demo.entity.UserInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 获取当前session
 *
 * @author CY
 * @date 2023/03/15 09:09
 **/
public class SessionUtil {
    public static UserInfo getSession(HttpServletRequest request) {
        final HttpSession session = request.getSession(false);
        final UserInfo userInfo = (UserInfo) session.getAttribute(Constant.SESSION_USERINFO_KEY);
        if (userInfo != null && userInfo.getId() > 0) {
            return userInfo;
        }
        return null;
    }
}
